package com.sunwayhorizo.health.hl7.rim;

import com.sunwayhorizo.health.common.*;
import com.sunwayhorizo.health.hl7.common.*;
import com.sunwayhorizo.health.hl7.datatypes.*;
import com.sunwayhorizo.health.hl7.factories.*;
import com.sunwayhorizo.health.hl7.persistent.*;
import java.io.*;
import java.sql.Timestamp;
import javax.persistence.*;
import org.jboss.seam.annotations.*;
import static com.sunwayhorizo.health.hl7.vocabulary.EntityCdSetCode.*;

@Name("NonPersonLivingSubject")
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("NLIV")
public class NonPersonLivingSubject extends LivingSubject implements Serializable
{

    // public CE genderStatusCode;
    // public ED strainText;

    /**
     * 
     */
    private static final long serialVersionUID = 1L;


    public NonPersonLivingSubject() throws Hl7Exception
    {
    }


    public NonPersonLivingSubject(ReferenceModifier referencemodifier)
    {
        super(referencemodifier);
    }


    public void setGenderStatusCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreEntyCdSets(ce, GENDERSTATUSCODE);
        }
        else
        {
            this.setNpGenderStatusCodeEtsId(ce.code().toString());
        }
    }


    public CE getGenderStatusCode() throws Hl7Exception
    {
        if (this.getNpGenderStatusCodeEtsId().equals(GENDERSTATUSCODE.toString()))
        {
            for (RimCoreEntyCdSets entityCdSets : this.getEntyCdSetsList())
            {
                if (this.getNpGenderStatusCodeEtsId().equals(entityCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(entityCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getNpGenderStatusCodeEtsId());
        return null;
    }


    public void setStrainText(ED strainText)
    {
        // RimCoreEds ed = new RimCoreEds();
        RimCoreEds ed = this.getRimCoreEdsNpStrainTextId();
        ed.setEdClob(strainText.literal().toString().toCharArray());
        ed.setMediaTypeCode(strainText.mediaType().toString());
        ed.setCharacterSetCode(strainText.charset().toString());
        ed.setLanguageCode(strainText.language().toString());
        ed.setCompressionCode(strainText.compression().toString());
        ed.setRefTelAddressTxt(strainText.reference().address().toString());
        ed.setRefTelSchemeCode(strainText.reference().scheme().toString());
        ed.setRefTelStartDateTs(new Timestamp(strainText.reference().useablePeriod().hull().low().toDate().getTime()));
        ed.setRefTelEndDateTs(new Timestamp(strainText.reference().useablePeriod().hull().high().toDate().getTime()));
        ed.setRefTelGtsTxt(strainText.reference().useablePeriod().literal().toString());
        ed.setEdRefTelUses(strainText.reference().use().toSet());
        ed.setIntegrityCheckAlgCode(strainText.integrityCheckAlgorithm().toString());
        ed.setIntegrityCheckTxt(strainText.integrityCheck().stringValue());
        // ed.addRimCoreEdsNpStrainTextId(this);
        this.setRimCoreEdsNpStrainTextId(ed);
    }


    public ED getStrainText() throws Hl7Exception
    {
        RimCoreEds ed = this.getRimCoreEdsNpStrainTextId();
        return DataTypeUtil.getED(new String(ed.getEdClob()));
    }

    // NonPersonLivingSubject
    @Column(name = "NP_STRAIN_TEXT_ED_ID")
    private Long npStrainTextEdId;
    @Column(name = "NP_GENDER_STATUS_CODE_ETS_ID")
    private String npGenderStatusCodeEtsId = GENDERSTATUSCODE.toString();


    @SuppressWarnings("unused")
    private void setNpStrainTextEdId(Long npStrainTextEdId)
    {
        this.npStrainTextEdId = npStrainTextEdId;
    }


    @SuppressWarnings("unused")
    private Long getNpStrainTextEdId()
    {
        return npStrainTextEdId;
    }


    private void setNpGenderStatusCodeEtsId(String npGenderStatusCodeEtsId)
    {
        this.npGenderStatusCodeEtsId = npGenderStatusCodeEtsId;
    }


    private String getNpGenderStatusCodeEtsId()
    {
        return npGenderStatusCodeEtsId;
    }

}
